<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <my-parent></my-parent>
  </div>
</body>
<template id="parent">
  <div>
    <h1>父组件</h1>
    <my-child ref="test"/>
  </div>
</template>
<template id="child">
  <div>
    <h4>子组件</h4>
  </div>
</template>
<script src="lib/vue.js"></script>
<script>
  // parent
  // 子组件可以通过 this.$parent 获取到父组件的实例
  const Child = {
    template: '#child',
    mounted () {
      console.log(this.$parent.parentMsg,"00")
      this.$parent.parentFn()
    }
  }
  const Parent = {
    template: '#parent',
    components: {
      MyChild: Child
    },
    data () {
      return {
        parentMsg: 'parent的msg'
      }
    },
    methods: {
      parentFn () {
        console.log(this.parentMsg)
      }
    }
  }

  new Vue({
    el: '#app',
    components: {
      MyParent: Parent
    }
  })
</script>
</html>